extends Node

enum Sound {HIT, FIRE, UI}
@export var audio_players: Array[AudioStreamPlayer]

var sounds : Dictionary[Sound, AudioStream] = {
	Sound.HIT : preload("uid://blonjlaa37md0"),
	Sound.FIRE : preload("uid://g72hyxdnaath"),
	Sound.UI : preload("uid://6nolwqlami52")
}

func player_sound(type: Sound) -> void:
	var audio_player := get_free_audio_player()
	if not audio_player:
		return
	audio_player.stream = sounds[type]
	audio_player.pitch_scale = randf_range(0.8, 1.3)
	audio_player.play()
	
func get_free_audio_player() -> AudioStreamPlayer:
	for player in audio_players:
		if not player.playing:
			return player
	return
